import os
import json

dir1 = sorted(os.listdir('/media/adt/ZWH4T/ZWH/bags/dataset/tm4/work_space/annotate_ok/anno___2023-05-28-17-23-20_filter0-car/lidar'))
dir2 = sorted(os.listdir('/media/adt/ZWH4T/ZWH/bags/dataset/tm4/work_space/datasets_0/__2023-05-28-17-23-20_filter0-car/lidar_bin'))
file1 = []
for dir in dir1:
    file1.append(dir[:-3])
file2 = []
for dir in dir2:
    file2.append(dir[:-3])
with open('/media/adt/ZWH4T/ZWH/bags/dataset/tm4/work_space/datasets_0/__2023-05-28-17-23-20_filter0-car/samples/samples.json', 'r') as f:
    samples = json.load(f)
samples['key_index'] = []

for file in file1:
    if file in file2:
        idx = file2.index(file)
        samples['key_index'].append(idx)
    else:
        raise ValueError

with open('/media/adt/ZWH4T/ZWH/bags/dataset/tm4/work_space/datasets_0/__2023-05-28-17-23-20_filter0-car/samples/samples.json', 'w') as f:
    json.dump(samples, f)
